import java.util.Arrays;
import java.util.Objects;

public class HashBuck<V,K> {


    static class Node<V,K>{
        public V key;
        public K value;
        public Node<V,K> next;

        public Node(V key, K value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node<?, ?> node = (Node<?, ?>) o;
            return Objects.equals(key, node.key);
        }

        @Override
        public int hashCode() {
            return Objects.hash(key, value, next);
        }
    }

    public Node<V,K>[] array;
    public int UseSize;
    public static final double Double_flog = 0.75;

    public HashBuck() {
        this.array = (Node<V,K>[])new Node[10];
    }

    public void put(V key,K value) {
        Node<V,K> node = new Node<>(key,value);
        int code = key.hashCode();
        int index = code % array.length;

        Node<V,K> cur = array[index];

        while(cur != null) {
            if(cur.key.equals(key)) {
                cur.value =value;
                return;
            }
            cur = cur.next;
        }

        node.next = array[index];
        array[index] = node;
        UseSize++;

        if(fax() > Double_flog) {
            reSize();
        }


    }

    private int fax() {

        return UseSize % array.length;
    }

    private void reSize() {
        Node<V,K>[] CurNext = ( Node<V,K>[])new Node[array.length * 2];

        for (int i = 0; i < array.length; i++) {

            Node<V,K> cur = array[i];
            while(cur != null) {
                int code = cur.key.hashCode();
                int index = code % array.length;
                Node<V,K> prev = cur.next;
                cur.next = array[index];
                array[index] = cur;
                cur = prev;
            }
        }
        array = CurNext;
    }


    public K get(V key) {

            int code = key.hashCode();
            int index = code % array.length;
            Node<V,K> cur = array[index];

            while(cur != null) {
                if(cur.value.equals(key)) {
                    return cur.value;
                }
                cur =cur.next;
            }


        return null;
    }
}
